<?php
namespace Admin\Controller;


class AdvinfoController extends BaseController{
	public $pagesize=10;
	public $currentpage=1;
	public $where='ischeck=0';
	function advOper(){
		
		if(!empty($_FILES)){
			
			$pdoUpload = new \Think\Upload();
			//设置配置
			$pdoUpload->mimes=array('image/jpeg','image/png','image/gif');
			$pdoUpload->autoSub=false;
			$pdoUpload->rootPath= "./Public/upload/adv/";
			$re = $pdoUpload->upload();			
			if($re){//判断图片上传是否成功				
				if(!empty($_POST)){
					$_POST['imagename']=$re['file_0']['savename'];
					$pdo = D('advinfo');
					
					$ce=$pdo->create();
					if($ce){
						$result = $pdo->add();
						if($result){//图片上传成功，数据上传成功
							$info =1;
							$this->assign('info',$info);
						}else{//图片上传成功，数据上传失败
							$info =2;
							$this->assign('info',$info);
						}
					}else{//数据创建失败
						$error = $pdo->getError();
						$info =3;
						$this->assign('info',$info);
						$this->assign('error',$error);
					}
				}
				
			}else{//图片上传失败
				$info =4;
								
				$this->assign('info',$info);		
			};
		
		}
		
		$this->display();
	}
	
	/*
	 * @discribe 广告分类管理
	 */	
	function navOper(){
		$pdo = D('Advinfo');
		
		//获得总的记录条数，计算出总的页面
		$count = $pdo->count();
		$this->assign('count',$count);
		//获取分页显示的起始值
		if(empty($_GET)){
			
			$start = ($this->currentpage-1)*$this->pagesize;
			$pdoArr = $pdo->limit("$start,$this->pagesize")->select();
			
		
		}else{
			if(isset($_GET['currentpage'])){
				$this->currentpage = $_GET['currentpage'];
			};
			if(isset($_GET['pagesize'])){
				$this->pagesize = $_GET['pagesize'];
			};
			
			$start = ($this->currentpage-1)*$this->pagesize;
			$pdoArr = $pdo->limit("$start,$this->pagesize")->select();
			
		}
		foreach ($pdoArr as $k=>$v){//查询广告分类
			$pdotype = D('advtype');
			$typeArr = $pdotype->field('typename')->where(array('id'=>$v['typename']))->select();
			$pdoArr[$k]['typename'] = $typeArr[0]['typename'];
		
		};
		
		$this->assign('pdoArr',$pdoArr); 
		$this->display();
	}
	/*
	 * @discribe 广告分类添加
	*/
	function navOperAdd(){
		if(!empty($_POST)){
			$_POST['time']=time();
			$pdo = D('Advtype');
			
			$ce = $pdo->create();
			if($ce){
				$re = $pdo->add();
				if($re){
					$info = array('mes'=>1,'content'=>'添加成功！');
					$this->ajaxReturn($info);
				}else{
					$info = array('mes'=>2,'content'=>'添加失败！');
					$this->ajaxReturn($info);
				}
			}else{
				$error=$pdo->getError();
				$info=array('mes'=>3,'content'=>$error);
				$this->ajaxReturn($info);
			}
		}
	}
		
}